//
//  PortraitViewController.m
//  Intake
//
//  Created by vandong on 9/26/13.
//  Copyright (c) 2013 Mac Center. All rights reserved.
//

#import "PortraitViewController.h"
#import "SupportFunctions.h"
#import "LanscapeViewController.h"

@interface PortraitViewController ()
{
    LanscapeViewController *landscape;
}
@end

@implementation PortraitViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (float)degrees2radians:(float)d
{
    float r = d * (M_PI / 180);
    return r;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
//    UIViewController *viewController    = [[UIViewController alloc] init];
//    viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//    [self presentViewController:viewController animated:NO completion:^{
//        [self dismissViewControllerAnimated:NO completion:nil];
//    }];
    
//    landscape = [LanscapeViewController new];

    // Do any additional setup after loading the view, typically from a nib.
    
    CGAffineTransform sliderRotation = CGAffineTransformIdentity;
    sliderRotation = CGAffineTransformRotate(sliderRotation, -(M_PI / 2));
    
    CGRect rect = self.slideBreakfast.frame;
    rect.origin.x = self.lbBreakfast.center.x - rect.size.width/2;// self.lbBreakfast.frame.origin.x - rect.size.width/2 + self.lbBreakfast.frame.size.width/2;
    rect.origin.y = self.lbBreakfast.frame.origin.y - rect.size.width/2 - 3 *self.lbBreakfast.frame.size.height;
    self.slideBreakfast.frame = rect;
    
    rect = self.slideLunch.frame;
    rect.origin.x = self.lbLunch.center.x - rect.size.width/2;// self.lbLunch.frame.origin.x - rect.size.width/2 + self.lbLunch.frame.size.width/2;
    rect.origin.y = self.lbLunch.frame.origin.y - rect.size.width/2 - 3 *self.lbBreakfast.frame.size.height;
    self.slideLunch.frame = rect;
    
    rect = self.slideDinner.frame;
    rect.origin.x = self.lbDinner.center.x - rect.size.width/2;// self.lbDinner.frame.origin.x/2 - rect.size.width/2 + self.lbDinner.frame.size.width/2;
    rect.origin.y = self.lbDinner.frame.origin.y - rect.size.width/2 - 3 *self.lbBreakfast.frame.size.height;
    self.slideDinner.frame = rect;
    
    rect = self.slideSnack.frame;
    rect.origin.x = self.lbSnack.center.x - rect.size.width/2;// self.lbSnack.frame.origin.x/2 - rect.size.width/2 + self.lbSnack.frame.size.width/2;
    rect.origin.y = self.lbSnack.frame.origin.y - rect.size.width/2 - 3 *self.lbBreakfast.frame.size.height;
    self.slideSnack.frame = rect;
    
    self.slideBreakfast.transform = sliderRotation;
    self.slideLunch.transform = sliderRotation;
    self.slideDinner.transform = sliderRotation;
    self.slideSnack.transform = sliderRotation;
    
}

- (void)viewDidAppear:(BOOL)animated {
    
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (IBAction)sliderValueChanged:(UISlider *)sender
{
    self.lbCurrentDragValue.text = [NSString stringWithFormat:@"%d", (int)sender.value];
    float total = self.slideBreakfast.value + self.slideLunch.value + self.slideDinner.value+ self.slideSnack.value;
    float totalOfMax = self.slideBreakfast.maximumValue + self.slideLunch.maximumValue + self.slideDinner.maximumValue+ self.slideSnack.maximumValue;
    self.lbCurTotal.text = [NSString stringWithFormat:@"%d", (int)total];
    self.lbCurPercent.text = [NSString stringWithFormat:@"%d%@", (int)total / (int)totalOfMax, @"%"];
//    self.display.text = [NSString stringWithFormat:@"%d", (int)sender.value];
//    CGAffineTransform labelRotation = CGAffineTransformIdentity;
//    labelRotation = CGAffineTransformRotate(labelRotation, [self degrees2radians:sender.value]);
//    self.display.transform = labelRotation;
}

- (IBAction)sliderTouchUpInside:(id)sender {
    self.lbCurrentDragValue.text = [NSString stringWithFormat:@"%d", 0];
}


#pragma mark - orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
	//	(iOS 5)
	//	Only allow rotation to portrait
    
	return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}


//- (BOOL)shouldAutorotate
//{
//	//	(iOS 6)
//	//	No auto rotating
//	return NO;
//}
//
//- (NSUInteger)supportedInterfaceOrientations
//{
//    //	(iOS 6)
//    //	Only allow rotation to portrait
//    return UIInterfaceOrientationMaskPortrait;
//}
//
//- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
//{
//	//	(iOS 6)
//	//	Force to portrait
//	return UIInterfaceOrientationPortrait;
//}
//
// 
//-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
//        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
//        
//        [self.navigationController pushViewController:landscape animated:NO];
//        
//    }
//}
@end
